package com.qf.commerce.controller;

import com.github.pagehelper.PageInfo;
import com.qf.commerce.common.dto.FreightTemplateDto;
import com.qf.commerce.common.dto.WarehouseDto;
import com.qf.commerce.common.vo.FreightTemplateVo;
import com.qf.commerce.common.vo.WarehouseVo;
import com.qf.commerce.resp.ResponseResult;
import com.qf.commerce.service.AreaService;
import com.qf.commerce.service.TemplateService;
import com.qf.commerce.service.WarehouseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Administrator
 */
@RestController
@RequestMapping("/logistics")
@Api(tags = "物流管理Api接口文档")
public class LogisticsController {
    @Resource
    WarehouseService warehouseService;
    @Resource
    AreaService areaService;
    @Resource
    TemplateService templateService;

    @PostMapping("/warehouse/add")
    @ApiOperation("根据仓库请求参数对象添加仓库")
    public ResponseResult<Integer> addWarehouse(@RequestBody WarehouseDto warehouseDto){
        try{
            return ResponseResult.success(warehouseService.addWarehouse(warehouseDto));
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }

    @PutMapping("/warehouse/update")
    @ApiOperation("根据仓库请求参数对象修改仓库")
    public ResponseResult<Integer> modifyWarehouse(@RequestBody WarehouseDto warehouseDto){
        try {
            return ResponseResult.success(warehouseService.modifyWarehouse(warehouseDto));
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }

    @DeleteMapping("/warehouse/delete")
    @ApiOperation("根据仓库ID假删除仓库")
    @ApiImplicitParam(name = "warehouseId",value = "仓库ID",required = true,paramType = "query")
    public ResponseResult<Integer> deleteWarehouse(@RequestParam("warehouseId") Long warehouseId){
        try {
            return ResponseResult.success(warehouseService.deleteWarehouse(warehouseId));
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }

    @DeleteMapping("/warehouse/deletes")
    @ApiOperation("根据仓库ID批量假删除仓库")
    @ApiImplicitParam(name = "warehouseIds",value = "仓库ID集合",required = true,paramType = "query")
    public ResponseResult<Integer> deleteWarehouses(@RequestParam("warehouseIds") List<Long> warehouseIds){
        try {
            return ResponseResult.success(warehouseService.deleteWarehouses(warehouseIds));
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }
    @PutMapping("/warehouse/switch_deliver")
    @ApiOperation("根据仓库请求参数对象切换发货点状态")
    public ResponseResult<Integer> switchDeliverStatus(@RequestBody WarehouseDto warehouseDto){
        try {
            return ResponseResult.success(warehouseService.switchDeliverStatus(warehouseDto));
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }

    @PutMapping("/warehouse/switch_receive")
    @ApiOperation("根据仓库请求参数对象切换收货点状态")
    public ResponseResult<Integer> switchReceiveStatus(@RequestBody WarehouseDto warehouseDto){
        try {
            return ResponseResult.success(warehouseService.switchReceiveStatus(warehouseDto));
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }

    @GetMapping("/warehouse/list")
    @ApiOperation("展示仓库列表")
    public ResponseResult<PageInfo<WarehouseVo>> queryWarehouseList(){
        try {
            return ResponseResult.success(warehouseService.queryWarehouseList());
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }

    @PostMapping("/template/add")
    @ApiOperation("根据运费模板请求参数对象添加运费模板")
    public ResponseResult<Integer> addTemplate(@RequestBody FreightTemplateDto freightTemplateDto){
        try{
            return ResponseResult.success(templateService.addTemplate(freightTemplateDto));
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }

    @PutMapping("/template/update")
    @ApiOperation("根据运费模板请求参数对象修改运费模板")
    public ResponseResult<Integer> modifyTemplate(@RequestBody FreightTemplateDto freightTemplateDto){
        try{
            return ResponseResult.success(templateService.modifyTemplate(freightTemplateDto));
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }

    @DeleteMapping("/template/delete")
    @ApiOperation("根据运费模板ID假删除运费模板")
    @ApiImplicitParam(name = "templateId",value = "运费模板ID",required = true,paramType = "query")
    public ResponseResult<Integer> deleteTemplate(@RequestParam("templateId") Long templateId){
        try{
            return ResponseResult.success(templateService.deleteTemplate(templateId));
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }

    @GetMapping("/template/list")
    @ApiOperation("展示运费模板列表")
    public ResponseResult<PageInfo<FreightTemplateVo>> queryTemplateList(){
        try{
            return ResponseResult.success(templateService.queryTemplateList());
        }catch (Exception e){
            return ResponseResult.fail();
        }
    }



}
